/*
	Template Name: ARCHITEC
	Template URI: http://themeforest.net/user/designare
	Author: DesignareThemes
*/

$(window).load(function(){
	$('img').animate({
		'opacity': '1',
		'filter': 'alpha(opacity = 100)'
	}, 1000);
	
	/* OVERLAY GOOGLE MAPS */
	//$("#map a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',theme:'dark_square',slideshow:5000});
		
	
});

$(document).ready(function() {

		
	$('img').each(function(){
	var special = false;
		if (!($(this).parent().hasClass('nivoSlider')) && $(this).parent().attr('id') != 'single_image' && !($(this).hasClass('avatar')) && !($(this).hasClass('slideimg')) && !($(this).parent().parent().hasClass('image')) ){
			special = true;
			var rand_id = parseInt(Math.random()*10000);
			var rand_id = "img-"+rand_id;
			$(this).addClass(rand_id.toString());
			var top = ($(this).parent().parent().height()-16)/2;
			var left = ($(this).parent().parent().width()-16)/2;
			var templatedirectory = $('#templatedirectory').html();
			var html = $(this).parent().parent().html();
			var img_loader = '<div class="img_loader" style="float: left !important; clear:none !important; position: absolute; clear:none; z-index: 999; margin-top: '+ top +'px; margin-left: '+ left +'px; width: 16px; height: 16px; background: url('+ templatedirectory +'/css/themes/default/loading.gif);"></div>';
			$(this).parent().parent().html(img_loader+html);
			$('.'+rand_id).load(function(){
				$(this).animate({
					'opacity': '1',
					'filter': 'alpha(opacity = 100)'
				}, 1000);
				$(this).parent().parent().children('.img_loader').remove();
			});
		}
		
		if ($(this).parent().attr('id') == 'single_image'){
			special = true;
			$(this).load(function(){
				$(this).animate({
					'background':'none',
					'opacity': '1',
					'filter': 'alpha(opacity = 100)'
				}, 1000);
			});
		}
		
		if ($(this).parent().parent().hasClass('image')){
			special = true;
			$(this).load(function(){
				$(this).animate({
					'background':'none',
					'opacity': '1',
					'filter': 'alpha(opacity = 100)'
				}, 1000);
			});
		}
		
		//if (!special){
			$(this).load(function(){
				$(this).animate({
					'opacity': '1',
					'filter': 'alpha(opacity = 100)'
				}, 1000);
			});
		//}
			
		$(this).load(function(){
			//$(this).parent().find('.img_loader').remove();
			$(this).animate({
				'opacity': '1',
				'filter': 'alpha(opacity = 100)'
			}, 1000);
			$('.image-single .hover-image').height( $('#single_image img').height() );
			$('.image-single .hover-image').css('margin-top', '-'+$('#single_image img').height()+'px' );
			var marginTops = ($('.image-single img').height()-75)/2;
			$('.image-single .lupa').css('top', marginTops+'px' );
		});
	});


	//correct heights vertical seps
	$('.vertical_sep').each(function(){
		var heights = $(this).parent().height() - 20;
		//alert(heights);
		$(this).css({
			'height': heights,
			'margin-top':'10px' 
		});

	});
				
		var tabelaHeight = $('.tabela div').offsetHeight;
		$('.tabela').height(tabelaHeight);
		
		//attention to main color scheme
		//CSS name of light theme: default_light.css
		//CSS name of dark theme: default_dark.css
		var btnhover = 'btnhover_toplink';
		var textcolor = '#fff';
		var background = '#171616';
		var templatepath = $("#templatedirectory").html();
				
		
		$('.menu-item').has('.sub-menu').addClass('menu-parent');
		$('.menu-parent').hover(function(){
			if ($(this).parent().attr('id') === "menu-menu"){
				if($("#c_scheme").val() == 'default_light'){
					btnhover = 'btnhover_toplink';
					textcolor = '#fff';
					background = '#171616';
					$('.sub-menu').find('a').addClass("lfade");					
				} else {
					btnhover = 'btnhover_toplink_dark';
					textcolor = '#000';
					background = '#fff';
					$('.sub-menu').find('a').addClass("lfade_dark");
				}
				$(this).children('a').css({
					'background':'url("' + templatepath  + '/img/'+ btnhover + '.png") no-repeat',
					'color': textcolor
				});
			} else {
			
				if($("#c_scheme").val() == 'default_light'){
					btnhover = 'btnseta';
					textcolor = '#fff';
					background = '#000';
					$('.sub-menu').find('a').addClass("lfade");
					
				} else {
					btnhover = 'btnseta_dark';
					textcolor = '#000';
					background = '#fff';
					$('.sub-menu').find('a').addClass("lfade_dark");
				}
			
				$(this).children('a').css({
					'background':''+background+' url("' + templatepath  + '/img/'+ btnhover + '.png") no-repeat 150px 11px',
					'color': textcolor
				});
			}
			
		}, function(){
			$(this).children('a').css({
				'background':'',
				'color':''
			});
		});
						
		//correct sub-menu alignment
		$('.sub-menu').css({
			'margin-top':'-29px',
			'margin-left':'170px',
			'z-index':'9999',
			'background': background
		});
		
		$('.sub-menu').find('.sub-menu').css({
			'margin-left':'-2px',
			'margin-top': '0px'
		});
	
	$('#twitter a').hover(
	function(){$(this).stop().animate({width:'17px'}, 400);
		$("#twitter_hover", this).stop().animate({width:'25px', opacity:'0.8'}, 400);
			}, function() {$(this).stop().animate({width:'17px'}, 400);
				$("#twitter_hover", this).stop().animate({width:'17px', opacity:'0'}, 400);
			})
			
	
	/* FADE LABEL INPUTS */
	$('.maila').dwFadingLinks({
		color: '#7E9046',
		duration: 700
	});
	$('.mail, .name, .email, .message').dwFadingLinks({
		color: '#fff',
		duration: 700
	});
	$('.text').dwFadingLinks({
		color: '#8f8f8f',
		duration: 700
	});
	
	/* FADE LINKS MENU */
	$('.lfade').dwFadingLinks({
		color: '#fff',
		duration: 400
	});
	
	$('.lfade_dark').dwFadingLinks({
		color: '#000',
		duration: 400
	});
	
	/* FADE SOCIAL */
	$('.face').dwFadingLinks({
		color: '#6281c0',
		duration: 400
	});
	$('.tw').dwFadingLinks({
		color: '#2dceff',
		duration: 400
	});
	/* FADE PROJECTS EFFECT */
	$('.leffect').dwFadingLinks({
		color: '#E8F2F6',
		duration: 400
	});
	/* FADE PROJECTS EFFECT */
	$('.designare').dwFadingLinks({
		color: '#8d8d8d',
		duration: 400
	});
		
	/* FADE IMAGES */
	$('.button, .facebook, .twitter, .mapimg, .workimg, .btnseework, .mapimg, .backthumbs, .moreinfo, .css_next, .css_prev, .css_prev_nav, .css_next_nav, .prev, .next, .seeproject, .lighton').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
	 	$(this).hover(function () {
	    $span.stop().fadeTo(500, 1);
	 	}, function () {
	   		$span.stop().fadeTo(500, 0);
	  	});
	});
		

	/* CHANGE BETWEEN NEWS */
	$(document).ready(function(){
		$('ul.links li').click(function() {

		//Set "selected" the LI clicked
		$('ul.links li').each(function(){
		$(this).removeClass("newsld");
		});
		$(this).addClass("newsld");
			  
		//Hide all news content
		$('.newscontent div.titledate').each(function(){
		$(this).css("display", "none");
		});
			  
		//Show only the news content that as been clicked with fadein effect
		var newsid = $(this).attr('id');
		//$("#div"+newsid).css("display", "");
		$("#div"+newsid).fadeToggle("slow", "linear");
		});
	});
	
	/*
$(function() {		
		// initialize scrollable with mousewheel support
		$(".scrollable").scrollable({ vertical: true, mousewheel: true });	
	});
*/
	
	/* FUNCTION FOR SHOW MORE INFO AND GO BACK ON PROJECTS PAGE .Designare.*/
	$(".openproject").css("display", "none");
	$("#projectmoreinfo").css("display", "none");
			
			$('.openproject div.project_content').each(function(){
			  $(this).css("display", "none");
			});
		
		
			$('ul.tj_gallery li, a.project_0').click(function() {
			  var totalproject = 0;	
			  
			  //Hide projects thumbnails
			  $('.gallery_projects').css("display", "none");
			  
			  //Hide all projects info content
			  $('.openproject div.project_content').each(function(){
			  	$(this).css("display", "none");
			  	totalproject++;
			  });
			  
			  //Show only the project content that as been clicked with fadein effect
			  if($(this).hasClass("project_0"))
			  	var projectid = "project_1";
			  else
			  	var projectid = $(this).attr('id');
			  var id = projectid.split('_');
			  var prevproj = parseInt(id[1])-1;
			  var nextproj = parseInt(id[1])+1;
			 
			 	//Prepare the arrows to change to previous or next project
			 	if(prevproj <= 0){
			 		$('span.css_prev').css('opacity', '.3');
			 		$('.proj_prev').css('display', 'none');
			 		$('span.css_prev').css('display', '');
			 	}
			 	else{
			 		$('span.css_prev').css('opacity', '1');
			 		$('.proj_prev').css('display', '');
			 		$('span.css_prev').css('display', 'none');
			 	}		  	

			  if(nextproj == (totalproject + 1)){
			 		$('span.css_next').css('opacity', '.3');
			 		$('.proj_next').css('display', 'none');
			 		$('span.css_next').css('display', '');
			  }
			 	else{
			 		$('span.css_next').css('opacity', '1');
			 		$('.proj_next').css('display', '');
			 		$('span.css_next').css('display', 'none');
			 	}
			  
			  $(".proj_prev").attr("id", "project_"+prevproj);
			  $(".proj_next").attr("id", "project_"+nextproj);
			  
			  //Open project
			  $("#divnav"+projectid).fadeToggle("slow", "linear");
			  $("#projectmoreinfo").css("display", "");
			  $("#proj_navigation").css("display", "");
			  $(".openproject").css("display", "");
			  
			});
			
			$('.backthumbs').click(function() {
			
			  $("#proj_navigation").css("display", "none");
			  $(".openproject").css("display", "none");
			  $("#projectmoreinfo").css("display", "none");
			  
			  $('.gallery_projects').fadeToggle("slow", "linear");
			  
			});
			
						  
			  $('.projectnav a.css_prev, .projectnav a.css_next').click(function() {
			  	var totalproject=0;
			  	
			  	//Hide all projects info content
				  $('.openproject div.project_content').each(function(){
				  	$(this).css("display", "none");
				  	totalproject++;
				  });
				  
				  var projectid = $(this).attr('id');
				  var id = projectid.split('_');
				  var prevproj = parseInt(id[1])-1;
			  	var nextproj = parseInt(id[1])+1;
				  
			 	if(prevproj <= 0){
			 		$('span.css_prev').css('opacity', '.3');
			 		$('.proj_prev').css('display', 'none');
			 		$('span.css_prev').css('display', '');
			 	}
			 	else{
			 		$('span.css_prev').css('opacity', '1');
			 		$('.proj_prev').css('display', '');
			 		$('span.css_prev').css('display', 'none');
			 	}		  	

			  if(nextproj == (totalproject + 1)){
			 		$('span.css_next').css('opacity', '.3');
			 		$('.proj_next').css('display', 'none');
			 		$('span.css_next').css('display', '');
			  }
			 	else{
			 		$('span.css_next').css('opacity', '1');
			 		$('.proj_next').css('display', '');
			 		$('span.css_next').css('display', 'none');
			 	}
	 	
		 		$(".proj_prev").attr("id", "project_"+prevproj);
			  $(".proj_next").attr("id", "project_"+nextproj);
			  
			  //Open project
			  $("#divnav"+projectid).fadeToggle("slow", "linear");
			  $("#proj_navigation").css("display", "");
			  $(".openproject").css("display", "");
			  $("#projectmoreinfo").css("display", "");

			  });
			  
			  $('.projects ul li').hover(function(){
					$(".descript", this).stop().animate({top:'140px'},{queue:false,duration:160});
				}, function() {
					$(".descript", this).stop().animate({top:'187px'},{queue:false,duration:160});
				});	
	/*END MORE INFO PROJECTS*/

});